#include "globals.h"
#define NO_PARSE FALSE
#define NO_ANALYZE FALSE
#define NO_CODE FALSE

#include "util.h"
#if NO_PARSE
#include"scan.h"
#else
#include"parse.h"
#endif

int lineno = 0;
FILE* source;
FILE* listing;
FILE* code;

int EchoSource = TRUE;
int TraceScan = TRUE;
int TraceParse = TRUE;
int TraceAnalyze = FALSE;
int TraceCode = FALSE;

int Error = FALSE;

int main( int argc ,char* argv[]) {
	TreeNode* syntaxTree;
	char pgm[200];
	if (argc != 2) {
		fprintf(stderr, "usage: %s <filename>\n", argv[0]);
			//exit(1);
	}
	//strcpy(pgm, argv[1]);
	fprintf(stdout, "input the file\n");
	scanf("%s", pgm);
	if (strchr(pgm, '.') == NULL) 
		strcat(pgm, ".tiny");
	source = fopen(pgm, "r");
	if (source == NULL)
	{
		fprintf(stderr, "File %s not found\n", pgm);
	}
	listing = stdout;
	fprintf(listing, "\n TINY COMPLILATION :%s\n", pgm);

#if NO_PARSE
	while (getToken() != ENDFILE);
	
#else
	syntaxTree = parse();
	if (TraceParse) {
		fprintf(listing, "\nSyntax tree:\n");
		printTree(syntaxTree);
	}
	//system("pause");

#endif
	fclose(source);
	return 0;

}
